
const htmlWebpackPlugin = require('html-webpack-plugin')
const miniExtractCss = require('mini-css-extract-plugin')

module.exports = {
  entry: "./src/main.js",
  mode: "development",
  devtool: 'inline-source-map',
  devServer: {
    open: true
  },


  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [

          //   {
          //     loader: "style-loader" // 将 JS 字符串生成为 style 节点
          // }, 
          {
            loader: miniExtractCss.loader
          },
          {
            loader: "css-loader" // 将 CSS 转化成 CommonJS 模块
          }, {
            loader: "sass-loader" // 将 Sass 编译成 CSS
          }]
      },

      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 100
            }
          }
        ]
      },
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
            plugins: ['@babel/plugin-transform-runtime']
          }
        }
      }
    ]
  },
  plugins: [
    new miniExtractCss({
      filename: '[name]-[hash].css'
    }),
    new htmlWebpackPlugin({
      template: './public/index.html',
      filename: 'index.html'
    }),
    new htmlWebpackPlugin({
      template: './public/index.html',
      filename: 'detail.html'
    })
  ]
}